package cn.itwangxiang.android.ui;

import java.util.ArrayList;
import java.util.List;

import cn.itwangxiang.android.R;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class Demo extends Activity {

	private ListView uiList = null;

	private int REQUESTCODE = 1;// 返回结果码

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.demo);

		uiList = (ListView) findViewById(R.id.listViewUI);
		uiList.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_expandable_list_item_1, getData()));

		uiList.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				Class TargetClass = null;
				switch (arg2) {
				case 0:
					TargetClass = DemoActivity.class;
					break;
				case 1:
					TargetClass = DemoLayout.class;
					break;
				case 2:
					TargetClass = DemoIntent.class;
					break;
				case 3:
					TargetClass = DemoBaiduMap.class;
					break;
				case 4:
					TargetClass = DemoHttp.class;
					break;
				case 5:
					TargetClass = DemoUIText.class;
					break;
				case 6:
					TargetClass = DemoUITab.class;
					break;
				case 7:
					TargetClass = DemoUIViewPager.class;
					break;
				case 8:
					TargetClass = DemoUIHSV.class;
					break;
				case 9:
					TargetClass = DemoHandler.class;
					break;
				case 10:
					TargetClass = DemoStorage.class;
					break;
				case 11:
					TargetClass = DemoPhoto.class;
					break;
				case 12:
					TargetClass = DemoRadio.class;
					break;
				default:
					break;
				}
				if (TargetClass != null) {
					if (TargetClass == DemoIntent.class) {// 意图的数据传递
						Intent intent = new Intent(Demo.this, TargetClass);
						intent.putExtra("name", "itwangxiang");
						intent.putExtra("age", 23);
						startActivityForResult(intent, REQUESTCODE);
						// startActivity(intent);
					} else {
						Intent intent = new Intent(Demo.this, TargetClass);
						startActivity(intent);
					}
				}
			}
		});
	}

	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == 2) {
			if (requestCode == REQUESTCODE) {
				String user = data.getStringExtra("user");
				Toast.makeText(Demo.this, "将用户信息完善后返回给当前：，" + user,
						Toast.LENGTH_LONG).show();
			}
		}
		if (resultCode == 3) {
			if (requestCode == REQUESTCODE) {
				ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);

				String clipboardMsg = "";
				try {
					clipboardMsg = cm.getPrimaryClip().getItemAt(0).getText()
							.toString();
				} catch (Exception e) {
				}
				Toast.makeText(Demo.this, "获取剪切板数据：" + clipboardMsg,
						Toast.LENGTH_LONG).show();
			}
		}
	}

	private List<String> getData() {

		List<String> data = new ArrayList<String>();
		data.add("1.Activity的生命周期");
		data.add("2.Layout布局");
		data.add("3.Intent的数据传递");
		data.add("4.API之百度地图");
		data.add("5.Http协议");
		data.add("6.常用的控件");
		data.add("7.Tab底部菜单");
		data.add("8.ViewPager滑动菜单");
		data.add("9.水平滚动");
		data.add("10.Handler机制");
		data.add("11.数据存储");
		data.add("12.上传图片");
		data.add("13.分组单选按钮");
		return data;
	}
}
